/*************************************************************************
 * File Name:    Permutations_II.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: 2013/11/4 0:28:18
 * 
 * Description:  
 |------------------------------------------------------------------------
 | Problem: Permutations II
 | Given a collection of numbers that might contain duplicates,
 | return all possible unique permutations.
 |
 | For example,
 | [1,1,2] have the following unique permutations:
 | [1,1,2], [1,2,1], and [2,1,1].
 |------------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

class Solution {
public:
    vector<vector<int> > permuteUnique(vector<int> &num)
    {
        vector<int> p(num.begin(), num.end());
        vector<vector<int> > ans;
        
        sort(p.begin(), p.end());
        do {
            ans.push_back(p);
        }while (next_permutation(p.begin(), p.end()));
        
        return ans; 
    }
};

